//index.js
//获取应用实例
// wxc3923a18b21ad187 f2u9xraw3p
// wx0da9b03433663f74 f4slf2nhkp
var wc = require('../../utils/wcache.js');
const bgMusicAudioContext = wx.getBackgroundAudioManager()
const {countDown} = require('../../utils/util');
var app = getApp()
Page({
  data: {
    slideImgUrls: [],
    goodShow: 2,
    indexTemp: "",
    showType: 'tool',
    shopLogo: "",
    shopGoods: [],
    showLoading: true,
    noMoretip: false,
    page: 0,
    isShowVideo: false,
    isShowreward: false,
    firstLoad:true,
    modelShow: false,
    isPullDownRefresh: false,
    isShowOrdertip:true,
    isShowFoldMenu:false,
    timer:null
  },
  onUnload(){
    this.data.timer && clearInterval(this.data.timer);
  },
  // onPageScroll(e){
  //   console.log(e);
  // },
  onLoad: function (e) {
    var that = this;
    app.setNavColor(that);
    if (!app.globalData.plumSession){
      app.plumSessionCallback = plumSession => {
        if (plumSession != '') {
          console.log('查询到登录信息');
          that.setData({
            isShowOrdertip: !that.data.isShowOrdertip
          })
          that.requestIndex();
          that.fenleiInfor();
          that.requestCoupon();
          that.requestPartners();
        } else {
          console.log('未查询到登录信息');
          app.wechatSq(that);
        }
      }
    }else{
      that.setData({
        isShowOrdertip: !that.data.isShowOrdertip
      })
      that.requestIndex();
      that.fenleiInfor();
      that.requestCoupon();
      that.requestPartners();
      // that.getSlient();
    }
  },
  onShow: function () {
    var that = this;
    if (that.data.titleName) {
      wx.setNavigationBarTitle({
        title: that.data.titleName
      });
    }
    if (app.globalData.plumSession) {
      app.contactData(that);
    }
    that.setData({
      followOpen: app.globalData.followOpen ? app.globalData.followOpen : 0
    })
    console.log(that.data.isShowOrdertip);
    app.setCartnum();//更新购物车数量
  },
  onReady: function () {
    var that = this;
    this.videoContext = wx.createVideoContext('myVideo');
    setTimeout(function () {
      wx.request({
        url: app.globalData.requestUrl,
        data: {
          map: 'applet_promotional_video'
        },
        success: function (res) {
          console.log(res.data);
          if (res.data.ec == 200) {
            var showPlaybtn = false;
            if (res.data.data.url != ''){
              showPlaybtn = true;
            }
            that.setData({
              videoInfo: res.data.data,
              showPlaybtn: showPlaybtn,
              musicUrl: res.data.data.musicUrl,
              musicTitle: res.data.data.musicTitle,
              vrurl: res.data.data.vrurl,
              vrShareTitle: res.data.data.vrShareTitle,
              vrShareCover: res.data.data.vrShareCover
            })
          } else {
            that.setData({
              showPlaybtn: false
            })
          }
        },
        complete: function () {
          wx.stopPullDownRefresh();
        }
      });
    }, 1)
  },
  initPage: function(){
    var that = this;
    that.onLoad();
    that.onShow();
  },
  // 计算当前时间到晚上零点之间的时间
  getNowtomr:function(){
    var cueDate = new Date();
    var remainTime = 86400 - (cueDate.getHours() * 60 * 60 + cueDate.getMinutes() * 60 + cueDate.getSeconds());
    return remainTime;
  },
  toVideo:function(e){
    var musicUrl = e.currentTarget.dataset.url;
    if (bgMusicAudioContext.paused === false) {
      bgMusicAudioContext.stop();
      app.globalData.curInfoMusicid = '';
      app.globalData.isPlay = false;
      app.globalData.isPlaynew = 'new';
    }
    wx.navigateTo({
      url: '/pages/video/video?url=' + musicUrl
    })
  },
  // 客服回复组件间传值
  getreplyData:function(e){
    console.log(e.detail);
    this.setData(e.detail);
  },
  hideGetuser: function () {
    var that = this;
    that.setData({
      isShowgetuser: false
    })
  },
  // 获取用户信息
  getuserInfo: function (e) {
    var that = this;
    if (e.detail.userInfo) {
      var userdata = e.detail;
      console.log(userdata);
      var slient = that.data.slient;
      var again = false;
      if (slient == 0) {
        again = true;
      }
      app.getuserInfo(that, userdata, again);
    }
  },
  getSlient:function(){
    var that = this;
    var slient = app.globalData.slient ? app.globalData.slient:'';
    that.setData({
      slient: slient
    })
    if (slient == 1) {
      // that.setData({
      //   isShowgetuser: true
      // })
      wx.hideTabBar()
    }
  },
  requestIndex: function (type) {
    var that = this;
    var page = that.data.page;
    //发起请求，获取列表列表
    wx.showLoading({
      title: '加载中',
    });
    wx.request({
      url: app.globalData.requestUrl,
      data: {
        map: 'applet_index_info',
        suid: app.globalData.suid,
        page: page,
        version: app.globalData.version,
        base: app.globalData.base,
        couponIndex: 1
      },
      success: function (res) {
        console.log(res.data.data);
        if (res.data.ec == 200) {
          var categoryList = app.splitArrData(res.data.data.shortcut, 10);
          var noticeList = app.splitArrData(res.data.data.noticeList,2);
          var kindsGoods = res.data.data.kind2Goods;
          for (var i = 0; i < kindsGoods.length; i++) {
            if (kindsGoods[i].kindData.length > 0) {
              if (kindsGoods[i].kindData[0].goods) {
                kindsGoods[i].selectedGoods = kindsGoods[i].kindData[0].goods;
              }
            } else {
              kindsGoods[i].selectedGoods = [];
            }
          }
          console.log(kindsGoods);
          var categoryGoods = res.data.data.categoryGoods;
          categoryGoods = categoryGoods ? categoryGoods : '';
          var curCategoryfl = '', curCategorygoods = '';
          if (categoryGoods) {
            if (categoryGoods.length > 0) {
              curCategoryfl = categoryGoods[0].id;
              curCategorygoods = categoryGoods[0].list;
            }
          }
          // 设置倒计时
          let popup = res.data.data.popup
          if(popup && popup.countdown){
            let time = new Date(popup.countdown.replace(/-/g,'/'))
            popup.countDownOb = countDown(time);
            that.countDownComputed();
          }
          that.setData({
            indexInfo: res.data.data,
            coupon:res.data.data.coupon,
            noticeInfo: res.data.data.notice,
            noticeList: noticeList?noticeList:[],
            kindsGoods: kindsGoods,
            shopLogo: res.data.data.logo,
            shopName: res.data.data.name,
            tempInfo: res.data.data.template,
            slideImgUrls: res.data.data.slide,
            shortMenu: res.data.data.shortcut,
            categoryList: categoryList,
            recommend: res.data.data.recommendGoods,
            categoryGoods: categoryGoods,
            curCategoryfl: curCategoryfl,
            curCategorygoods: curCategorygoods,
            kinds: res.data.data.kinds,
            goodShow: res.data.data.template.goodsStyle ? res.data.data.template.goodsStyle:'',
            titleName: res.data.data.template.title ? res.data.data.template.title : res.data.data.name,
            shareOpen: res.data.data.shareOpen,
            customerService: res.data.data.customerService,
            customerMobile: res.data.data.customerMobile,
            distribOpen: res.data.data.distribOpen,
            isPullDownRefresh: false,
            popup: popup
          });
          app.globalData.distribOpen = res.data.data.distribOpen;
          var sharedata = {
            shareOpen: res.data.data.shareOpen,
            shareUrl: res.data.data.shareUrl,
            shareTitle: res.data.data.template.title ? res.data.data.template.title : res.data.data.name 
          }
          app.globalData.sharedata = sharedata;
          var shareInfo = {
            shareCover: res.data.data.shareCover,
            shareTitle: res.data.data.shareTitle
          }
          app.globalData.shareInfo = shareInfo;

          // 存储是否开启客服
          app.globalData.customerService = res.data.data.customerService;
          if (res.data.data.customerService == 1) {
            if (app.globalData.userInfo) {
              var sessionForm = {
                "nickName": app.globalData.userInfo.nickName,
                "city": app.globalData.userInfo.city
              }
              app.globalData.sessionForm = JSON.stringify(sessionForm);
              that.setData({
                sessionForm: app.globalData.sessionForm
              })
              console.log(app.globalData.sessionForm);
            }
          }
          // 存储大转盘数据
          if (wc.get('firstLoad', 'empty') == 'empty') {
            if (res.data.data.lottery == 1) {
              that.setData({
                hasReward: 1,
                isShowreward: true
              })
              that.hideTimeAward();
              // 缓存现在到晚上零点的时间
              // var deadTime = parseInt(that.getNowtomr());
              // 缓存7天时间
              var deadTime = parseInt(7 * 24 * 60 * 60);//缓存过期时间
              wc.put('firstLoad', 'no', deadTime)
            }else{
              that.showImgjump();
            }
          } else {
            if (res.data.data.lottery == 1) {
              that.setData({
                hasReward: 1,
                isShowreward: false
              }) 
            };
            that.showImgjump();
          } 
          
          // 设置电话
          app.globalData.telphone = res.data.data.mobile;
          app.globalData.phoneOpen = res.data.data.phoneOpen;
          app.setPhoneopen(that);
          var namelogo = {
            name: res.data.data.name,
            logo: res.data.data.logo
          };
          app.globalData.namelogo = namelogo;
          if (res.data.data.template.title) {
            wx.setNavigationBarTitle({
              title: res.data.data.template.title
            });
          }
          if (res.data.data.template.temp == 48) {
            wx.setNavigationBarColor({
              frontColor: '#ffffff',
              backgroundColor: '#212223',
              animation: {
                duration: 400,
                timingFunc: 'easeIn'
              }
            })
          }
          var shopname = res.data.data.name;
          var allArr = [];
          var initArr = that.data.shopGoods;
          var curArr = res.data.data.goods;
          var lastPageLength = curArr.length;
          if (page > 0) {
            allArr = initArr.concat(curArr);
          } else {
            allArr = res.data.data.goods;
          }
          that.setData({
            shopGoods: allArr
          })
          if (lastPageLength < 10) {
            that.setData({
              noMoretip: true,
              showLoading: false
            });
          }
          console.log(that.data);
          wx.setStorage({
            key: "shopInfoname",
            data: shopname,
            success: function (e) {
              console.log("存储成功")
            }
          })
          wx.hideLoading();
        } else {
          console.log(res.data)
          if (page <= 0) {
            that.setData({
              shopGoods: []
            })
          } else {
            that.setData({
              noMoretip: true,
              showLoading: false
            });
          }
          wx.hideLoading();
        }
      },
      fail:function(){
        wx.hideLoading();
      },
      complete: function () {
        wx.stopPullDownRefresh();
      }
    });
  },

  countDownComputed(){
    this.data.timer = setInterval(()=>{
      let {countdown,countDownOb}  = this.data.popup;
      let time = new Date(countdown.replace(/-/g,'/'));
      this.setData({
        'popup.countDownOb': countDown(time)
      })
      if(countDownOb.day+countDownOb.hour+countDownOb.minute+countDownOb.second<=0){
        clearInterval(this.data.timer);
      }
    },1000);
  },
  
  requestPartners: function () {
    var that = this;
    var data = {};
    data.map = 'applet_three_configure_new';
    wx.request({
      url: app.globalData.requestUrl,
      data: data,
      success: function (res) {
        console.log(res.data);
        if (res.data.ec == 200) {
          that.setData({
            isShowFenxiao: res.data.data.isdistrib,
            isapply: app.globalData.isapply,
            userInfo: app.globalData.userInfo
          })
          console.log(that.data.isShowFenxiao);
          console.log(that.data.isapply);
          app.globalData.isdistrib = res.data.data.isdistrib;
          app.globalData.isapply = res.data.data.isapply;
        } else {
          // app.errorTip(that, res.data.em, 2000);
        }
      },
      complete: function () {
        wx.stopPullDownRefresh();
      }
    });
  },
  //快捷导航数据
  fenleiInfor: function () {
    var that = this;
    wx.request({
      url: app.globalData.requestUrl,
      data: {
        map: 'applet_applet_suspension_menu'
      },
      success: function (res) {
        console.log("快捷导航分类1222222");
        console.log(res.data);
        if (res.data.ec == 200) {
          console.log(res.data.data.indexMenu);
          that.setData({
            fenleiMenu: res.data.data.indexMenu.menu,
            fenleiTitle: res.data.data.indexMenu.title,
            fenleiOPen: res.data.data.indexMenu.open,
          })

          app.globalData.suspensionMenu = res.data.data.suspensionMenu;
          app.globalData.menuAllShow = res.data.data.suspensionMenuShow;
          var sessionForm = {};
          if (res.data.data.sessionForm) {
            sessionForm = {
              "nickName": app.globalData.userInfo.nickname,
              "city": app.globalData.userInfo.city
            }
          }
          app.globalData.btnImg = res.data.data.btnImg;
          app.globalData.sessionForm = JSON.stringify(sessionForm);
          app.globalData.isHasdata = true;
          app.globalData.indexUrl = res.data.data.indexUrl;
          app.globalData.telphone = app.globalData.telphone ? app.globalData.telphone : res.data.data.mobile;

          that.setData({
            isShowFoldMenu: true
          })
        } else {
          that.setData({
            fenleiMenu: []
          })
        }
      },
      complete: function () {
        wx.stopPullDownRefresh();
      }
    });
  },
  //快捷导航跳转
  openFenleiLink: function (e) {
    var that = this;
    var type = e.currentTarget.dataset.type;
    console.log(type);
    if (type == 'index') {
      wx.reLaunch({
        url: '/pages/singlePage/singlePage'
      })
    }
    if (type == '102') {
      var mobile = app.globalData.telphone ? app.globalData.telphone:'';
      if (mobile) {
        app.makeCallphone(mobile);
      } else {
        app.errorTip(that, "暂未获取到电话", 2000);
      }
    } else if (type == '103') {
      wx.navigateTo({
        url: '/pages/sharepage/sharepage'
      })
    } else if (type == '105') {
      that.requestSign();
    } else if (type == '3') {
      var url = e.currentTarget.dataset.url;
      var vrInfo = {
        vrurl: url
      }
      wx.setStorage({
        key: 'webviewUrl',
        data: vrInfo,
        success: function () {
          wx.navigateTo({
            url: '/pages/commonView/commonView',
          })
        }
      })
    } else if (type != '106' && type != '101') {
      var url = e.currentTarget.dataset.url;
      console.log(url);
      if(url){
        wx.navigateTo({
          url: url
        })
      }
    }
  },
  requestSign: function () {
    var that = this;
    wx.request({
      url: app.globalData.requestUrl,
      data: {
        map: 'applet_sign_get_point'
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.ec == 200) {
          app.errorTip(that, res.data.data.msg, 2000);
        } else {
          app.errorTip(that, res.data.em, 2000);
        }
      },
      complete: function () {
      }
    });
  },
  onPullDownRefresh: function () {
    var that = this;
    that.setData({
      page: 0,
      noMoretip: false,
      showLoading: true,
      isPullDownRefresh: true
    });
    // 下拉刷新背景音乐判断
    if (that.data.musicUrl && that.data.musicUrl != '') {
      console.log(app.globalData.curInfoMusicid);
      if (app.globalData.curInfoMusicid) {
        app.globalData.curInfoMusicid = '';
        that.setData({
          musicUrl: that.data.musicUrl,
          musicTitle: that.data.musicTitle
        })
      }
      app.globalData.isPlaynew = 'new';
      that.isPlayMusic();
    }
    that.onReady();
    that.onLoad();
    that.onShow();
    console.log("下拉刷新");
  },
  // 刷新判断是否播放音乐
  isPlayMusic: function () {
    var that = this;
    if (app.globalData.isPlay) {
      bgMusicAudioContext.stop();
      console.log("音乐播放状态刷新");
      bgMusicAudioContext.src = that.data.musicUrl;
      bgMusicAudioContext.title = that.data.musicName;
      bgMusicAudioContext.play();
      app.globalData.isPlaynew = '';
    } else {
      console.log("音乐暂停或者停止状态刷新");
      that.setData({
        musicUrl: that.data.musicUrl,
        musicTitle: that.data.musicTitle
      })
      bgMusicAudioContext.stop();
    }
  },
  onReachBottom: function () {
    var that = this;
    var temp = that.data.tempInfo.temp;
    if (temp == 3 || temp == 4) {
      console.log("到达页面底部")
      var isMore = that.data.noMoretip;
      var page = that.data.page;
      page++;
      that.setData({
        page: page
      });
      if (isMore) {
        console.log("已完成或正在加载");
      } else {
        that.requestIndex('bottomload');
      }
    }
  },
  // 打开商品列表
  openGoodList:function(e){
    var secondid = e.currentTarget.dataset.secondid;
    var title = e.currentTarget.dataset.title;
    wx.navigateTo({
      url: '/subpages1/allgoodsPage/allgoodsPage?secondid=' + secondid+'&title='+title
    })
  },
  goodDetail: function (e) {
    var goodId = e.currentTarget.dataset.id;
    if (goodId) {
      wx.navigateTo({
        url: '/subpages1/goodDetail/goodDetail?id=' + goodId
      })
    }
  },
  changeShowType: function (e) {
    var type = e.target.dataset.type;
    this.setData({
      showType: type
    })
  },
  searchPage: function () {
    wx.navigateTo({
      url: '/subpages1/searchList/searchList'
    })
  },
  allGoods: function (e) {
    var type = e.currentTarget.dataset.type;
    console.log(type);
    wx.setStorage({
      key: "cuxiao",
      data: type,
      success: function () {
        wx.navigateTo({
          url: '/subpages1/goodsList/goodsList'
        })
      }
    })
  },
  flGoods: function (e) {
    var id = e.currentTarget.dataset.id;
    console.log(id);
    if (id) {
      wx.navigateTo({
        url: '/pages/flGoodsList/flGoodsList?id=' + id
      })
    }
  },
  flAllgoods: function (e) {
    var secondid = e.currentTarget.dataset.secondid;
    var title = e.currentTarget.dataset.title;
    wx.navigateTo({
      url: '/subpages1/allgoodsPage/allgoodsPage?secondid=' + secondid + '&title=' + title
    })
  },
  shopNotice: function () {
    wx.navigateTo({
      url: '/subpages0/shopNotice/shopNotice'
    })
  },
  seemap: function (e) {
    var latitude = e.currentTarget.dataset.lat;
    var longitude = e.currentTarget.dataset.lng;
    var address = e.currentTarget.dataset.address;
    var name = e.currentTarget.dataset.name;
    wx.openLocation({
      latitude: Number(latitude),
      longitude: Number(longitude),
      name: name,
      address: address,
      scale: 18
    })
  },
  makeCall: function () {
    app.makeCall();
  },
  makePhone: function (e) {
    var mobile = e.currentTarget.dataset.mobile;
    app.makeCallphone(mobile);
  },
  playVideo: function () {
    var that = this;
    that.setData({
      isShowVideo: true
    })
    if (bgMusicAudioContext.paused === false) {
      bgMusicAudioContext.stop();
      app.globalData.curInfoMusicid = '';
      app.globalData.isPlay = false;
      app.globalData.isPlaynew = 'new';
    }
    this.videoContext.play();
  },
  hideVideo: function () {
    var that = this;
    that.setData({
      isShowVideo: false
    })
  },

  requestCoupon: function () {
    var that = this;
    wx.request({
      url: app.globalData.requestUrl,
      data: {
        map: 'applet_coupon_list'
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.ec == 200) {
          that.setData({
            couponList: res.data.data
          })
        } else {
          that.setData({
            couponList: []
          })
        }
      },
      complete: function () {
        wx.stopPullDownRefresh();
      }
    })
  },
  openSeckillList: function () {
    wx.navigateTo({
      url: '/subpages1/seckill/seckill',
    })
  },
  getCoupon: function (e) {
    var that = this;
    var curId = e.currentTarget.dataset.id;
    that.setData({
      curId: curId
    })
    app.getSubId(that, 'applet_coupon_receive', 'toGetCoupon');
  },
  // 领取优惠券跳转
  toGetCoupon: function (e) {
    var that = this;
    var id = that.data.curId;
    console.log(id);
    wx.showLoading({
      title: '领取中',
      mask: true
    })
    wx.request({
      url: app.globalData.requestUrl,
      data: {
        map: 'applet_coupon_receive',
        cid: id
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.ec == 200) {
          var couponInfo = {
            couponDetail: res.data.data.coupon,
            receiveList: res.data.data.receiveList
          };
          wx.setStorage({
            key: "couponInfo",
            data: couponInfo,
            success: function () {
              wx.navigateTo({
                url: '/subpages/useCoupon/useCoupon'
              })
            }
          })

        } else {
          app.errorTip(that, res.data.em, 2000);
        }
      },
      complete: function () {
        wx.hideLoading();
      }
    })

  },
  sharePage: function () {
    wx.navigateTo({
      url: '/pages/sharepage/sharepage'
    })
  },
  // 切换二级分类商品
  toggleSecondgoods: function (e) {
    var that = this;
    var kindsGoods = that.data.kindsGoods;
    var firstId = e.currentTarget.dataset.firstid;
    var goods = e.currentTarget.dataset.goods;
    for (var i = 0; i < kindsGoods.length; i++) {
      if (firstId == kindsGoods[i].id) {
        kindsGoods[i].selectedGoods = goods;
        console.log(kindsGoods[i].selectedGoods);
      }
    }
    that.setData({
      kindsGoods: kindsGoods
    })
  },
  toggleCategoryfl: function (e) {
    var id = e.target.dataset.id;
    var list = e.target.dataset.list;
    this.setData({
      curCategoryfl: id,
      curCategorygoods: list
    })
  },
  toinformationPage: function (e) {
    var title = e.currentTarget.dataset.title;
    wx.navigateTo({
      url: '/subpages1/informationPage/informationPage?title=' + title
    })
  },
  toApplyFenxiao: function () {//申请成为分销
    wx.navigateTo({
      url: '/pages/becomePartners/becomePartners'
    })
  },
  hideFenxiaotip: function () {
    var that = this;
    that.setData({
      isShowFenxiao: 1
    })
  },
  toCuslink: function (e) {
    var link = e.currentTarget.dataset.link;
    console.log(link);
    if(link){
      wx.navigateTo({
        url: link
      })
    }
  },
  toLottery: function () {
    wx.navigateTo({
      url: '/subpages/getReward/getReward',
    })
    // this.hideAward();
  },
  // 定时4s之后隐藏大转盘提示
  hideTimeAward: function () {
    var that = this;
    var isShowreward = that.data.isShowreward;
    if (isShowreward) {
      setTimeout(function () {
        that.hideAward();
      }, 5000)
    }
  },
  hideAward: function () {
    var that = this;
    that.setData({
      isShowreward: false
    });
    // var coupon = that.data.coupon;
    // console.log(coupon)
    // if (coupon.length>0){
    //   that.setData({
    //     modelShow: true
    //   })
    // }
    that.showImgjump();
  },
  //关闭首页的红包弹窗
  closeRedPacket: function () {
    var that = this;
    that.setData({
      modelShow: false
    })
  },
  showImgjump:function(){
    var that = this;
    var popup = that.data.popup;
    if (popup && popup.cover) {
      console.log("首页跳转弹窗00")
      var popupStorage = wx.getStorageSync('popupObj');
      var popupIsdiff = diff(popup, popupStorage);
      if (wc.get('popupfirstLoad', 'popupempty') == 'popupempty' || !popupIsdiff) {
        console.log('没有缓存或者缓存已到期或者首页配置改变');
        that.setData({
          popup: popup,
          showImgjump: true
        })
        var popupdeadTime = parseInt(popup.time);
        // if (popup.showType == 2) {
        //   // 缓存现在到晚上零点的时间
        //   var popupdeadTime = parseInt(that.getNowtomr());
        //   // var popupdeadTime = parseInt(100);
        // } else {
        //   // 缓存7天时间
        //   var popupdeadTime = parseInt(7 * 24 * 60 * 60);//缓存过期时间
        // }
        wc.put('popupfirstLoad', 'popupno', popupdeadTime)
        wx.setStorageSync('popupObj', popup)
      }else{
        console.log('已有缓存');
      }
    }
  },
  //关闭首页图片跳转弹窗
  closeImgjump: function () {
    var that = this;
    that.setData({
      showImgjump: false
    })
  },
  // VR视图
  toWebview: function (e) {
    var that = this;
    var vrurl = e.currentTarget.dataset.vrurl;
    var cover = e.currentTarget.dataset.cover;
    var title = e.currentTarget.dataset.title;
    var vrInfo = {
      vrurl: vrurl,
      cover: cover ? cover : '',
      title: title ? title : ''
    }
    wx.setStorage({
      key: 'webviewUrl',
      data: vrInfo,
      success: function () {
        wx.navigateTo({
          url: '/pages/commonView/commonView',
        })
      }
    })
  },
  // 优惠券
  toCouponlist: function () {
    wx.navigateTo({
      url: '/subpages/couponList/couponList'
    })
  },
  showMenu:function(){
    // wx.showShareMenu({
    //   withShareTicket:true,
    //   success:function(e){
    //     console.log(e);
    //   }
    // })
    console.log("更新消息为动态消息");
    wx.updateShareMenu({
      withShareTicket: true,
      isUpdatableMessage: true,
      activityId: '', // 活动 ID
      templateInfo: {
        parameterList: [{
          name: 'member_count',
          value: '1'
        }, {
          name: 'room_limit',
          value: '3'
        }]
      }
    })
  },
  onShareAppMessage: function (e) {
    wx.showShareMenu({
      withShareTicket: true
    })
    console.log('分享携带信息',e)
    
    if (e.target && e.target.dataset.isindex==1){
      var index = e.target.dataset.index;
      var couponList = this.data.couponList;
      couponList[index].needShare=0;
      this.setData({
        couponList: couponList
      })
    }
    var that = this;
    var title = that.data.titleName;
    var mid = app.globalData.userInfo.mid;
    console.log(title);
    var shareInfo = app.globalData.shareInfo;
    title = shareInfo.shareTitle ? shareInfo.shareTitle : title;
    var cover = shareInfo.shareCover ? shareInfo.shareCover : '';
    app.getPoint(that);
    return {
      title: title,
      imageUrl: cover,
      path: '/pages/index/index?scene='+mid
    }
  },
})
// 初始化图片高度
function setImageH(that) {
  var goodShow = that.data.goodShow;
  wx.getSystemInfo({
    success: function (res) {
      var imgWidth;
      if (goodShow == 1) {
        imgWidth = res.screenWidth * 0.95
      } else if (goodShow == 2) {
        imgWidth = res.screenWidth * 0.95 * 0.5
      }
      that.setData({
        imageWidth: imgWidth
      })
    }
  })
}
// 判断两个对象是否相等
function diff(obj1,obj2){
    var o1 = obj1 instanceof Object;
    var o2 = obj2 instanceof Object;
    if(!o1 || !o2){/*  判断不是对象  */
        return obj1 === obj2;
    }
    if(Object.keys(obj1).length !== Object.keys(obj2).length){
        return false;
    }
    for(var attr in obj1){
        var t1 = obj1[attr] instanceof Object;
        var t2 = obj2[attr] instanceof Object;
        if(t1 && t2){
            return diff(obj1[attr],obj2[attr]);
        }else if(obj1[attr] !== obj2[attr]){
            return false;
        }
    }
    return true;
}